home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / Sample Code / AppsToGo / DTS.Lib / DTS.Lib.headers / TextEditControl.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-24  |  17.6 KB  |  376 lines  |  [TEXT/MPS ]

  1. #ifndef __TEXTEDITCONTROL__
  2. #define __TEXTEDITCONTROL__
  3.  
  4. #ifndef __TYPES__
  5. #include <Types.h>
  6. #endif
  7.  
  8. #ifndef __TEXTEDIT__
  9. #include <TextEdit.h>
  10. #endif
  11.  
  12. #ifndef __TEXTSERVICES__
  13. #include <TextServices.h>    
  14. #endif
  15.  
  16. #ifndef    __TSMTE__
  17. #include "TSMTE.h"
  18. #endif
  19.  
  20. #ifndef __WINDOWS__
  21. #include <Windows.h>
  22. #endif
  23.  
  24. typedef Boolean    (*CTEKeyFilterProcPtr)(TEHandle teHndl, EventRecord *event, short *handled);
  25. typedef Boolean    (*CTEFastKeysProcPtr)(TEHandle teHndl, EventRecord *event);
  26.  
  27. typedef struct CTEDataRec {
  28.     short                maxTextLen;
  29.     Boolean                newUndo;
  30.     short                undoSelStart;
  31.     short                undoSelEnd;
  32.     Handle                undoText;
  33.     StScrpHandle        undoStyl;
  34.     short                mode;
  35.     Rect                brdrRect;
  36.     CTEKeyFilterProcPtr    keyFilter;
  37.     CTEFastKeysProcPtr    fastKeys;
  38.     TSMDocumentID        docID;
  39. } CTEDataRec;
  40. typedef CTEDataRec *CTEDataPtr, **CTEDataHndl;
  41.  
  42. pascal void        ASMNOCARET(Rect *caretRect);
  43. pascal Boolean    ASMTECLIKLOOP(void);
  44.     /* Entry-points for the assembly glue. */
  45.  
  46. void            CTEActivate(Boolean active, TEHandle teHndl);
  47.     /* Activate this TextEdit record.  If another is currently active, deactivate
  48.     ** that one.  The view control for this TextEdit record is also flagged to
  49.     ** indicate which was the last active one for this window.  If the previous
  50.     ** active TextEdit record was in the same window, then flag the old one off
  51.     ** for this window.  The whole point for this per-window flagging is so that
  52.     ** activate events can reactivate the correct TextEdit control per window. */
  53.  
  54. Boolean            CTEClick(WindowPtr window, EventRecord *event, short *action);
  55.     /* This is called when a mouseDown occurs in the content of a window.  It
  56.     ** returns true if the mouseDown caused a TextEdit action to occur.  Events
  57.     ** that are handled include if the user clicks on a scrollbar that is
  58.     ** associated with a TextEdit control.
  59.     **
  60.     ** if CTEClick returns false, action is 0
  61.     ** if CTEClick returns true,  action is:
  62.     **      -1 if control was activated by clicking on the TextEdit control or related scrollbar.
  63.     **       0 if control that was clicked on was already active. */
  64.  
  65. void            CTEClikLoop(void);
  66.     /* Do the cut-copy-paste-clear operations for the currently active
  67.     ** TextEdit control.  Caller assumes appropriateness of the call.  Typically,
  68.     ** this routine won't be called at an inappropriate time, since the menu
  69.     ** item should be enabled or disabled correctly.
  70.     ** Use CTEEditMenu to set the menu items undo-cut-copy-paste-clear correctly
  71.     ** for the active TextEdit control.  Since undo isn't currently supported,
  72.     ** all that CTEEditMenu does for the undo case is to deactivate it right now. */
  73.  
  74. ControlHandle    CTEClipboard(short menuID);
  75.     /* Do the cut-copy-paste-clear operations for the currently active
  76.     ** TextEdit control.  Caller assumes appropriateness of the call.  Typically,
  77.     ** this routine won't be called at an inappropriate time, since the menu
  78.     ** item should be enabled or disabled correctly.
  79.     ** Use CTEEditMenu to set the menu items undo-cut-copy-paste-clear correctly
  80.     ** for the active TextEdit control.  Since undo isn't currently supported,
  81.     ** all that CTEEditMenu does for the undo case is to deactivate it right now.
  82.     ** If a TextEdit control content changes due to this operation, the control
  83.     ** handle is returned. */
  84.  
  85. void            CTEConvertClipboard(Boolean convertClipboard, Boolean becomingActive);
  86.     /* Call this for activate events to manage importing and exporting the TextEdit local scrap. */
  87.  
  88. ControlHandle    CTECtlHit(void);
  89.     /* The TextEdit control that was hit by calling FindControl is saved in a
  90.     ** global variable, since the CDEF has no way of returning what kind it was.
  91.     ** To determine that it was a TextEdit control that was hit, first call this
  92.     ** function.  The first call returns the old value in the global variable,
  93.     ** plus it resets the global to nil.  Then call FindControl(), and then
  94.     ** call this function again.  If it returns nil, then a TextEdit control
  95.     ** wasn't hit.  If it returns non-nil, then it was a TextEdit control that
  96.     ** was hit, and specifically the one returned. */
  97.  
  98. void            CTEDispose(TEHandle teHndl);
  99.     /* Disposes of the TERecord, TextEdit control, and any related scrollbars. */
  100.  
  101. TEHandle        CTEDisposeView(ControlHandle viewCtl);
  102.     /* Dispose of the view control and related scrollbars.  This function also
  103.     ** returns the handle to the TextEdit record, since it was just orphaned.
  104.     ** Use this function if you want to get rid of a TextEdit control, but you
  105.     ** want to keep the TextEdit record. */
  106.  
  107. short            CTEDocHeight(TEHandle teHndl);
  108.     /* Returns the full document height. */
  109.  
  110. Boolean            CTEEditMenu(Boolean *activeItem, short editMenu, short undoID, short cutID);
  111.     /* Enable or disable edit menu items based on the active TextEdit control.
  112.     ** You pass the menu ID of the undo item in undoID, and the menu ID of the
  113.     ** cut item in cutID.  If undoID or cutID is non-zero, then some action is
  114.     ** performed.  If you pass a non-zero value for cutID, then the other menu
  115.     ** items cut-copy-paste-clear are updated to reflect the status of the
  116.     ** active TextEdit control. */
  117.  
  118. Boolean            CTEEvent(WindowPtr window, EventRecord *event, short *action);
  119.     /* Handle the event if it applies to the active TextEdit control.  If some
  120.     ** action occured due to the event, return true.
  121.     **
  122.     ** if event not handled, false is returned and action is 0
  123.     ** if event handled, true is returned and action is:
  124.     **      -1: an inactive control was clicked on and it was made active.
  125.     **       0: an active control was clicked on and tracked.
  126.     **       1: the control took the keypress, but no change occured to the TERecord.
  127.     **       2: the control took the keypress and the TERecord changed. */
  128.  
  129. TEHandle        CTEFindActive(WindowPtr window);
  130.     /* Returns the active TextEdit control, if any.  If nil is passed in, then
  131.     ** the return value represents whatever TextEdit control is active, independent
  132.     ** of what window it is in.  If a window is passed in, then it returns a
  133.     ** TextEdit control only if the active control is in the specified window.
  134.     ** If the active TextEdit control is in some other window, then nil is returned. */
  135.  
  136. ControlHandle    CTEFindCtl(WindowPtr window, EventRecord *event, TEHandle *teHndl,
  137.                            ControlHandle *ctlHit);
  138.     /* This determines if a TextEdit control was clicked on directly.  The control found
  139.     ** and returned is the TextEdit control.  The control hit may be the same, or it may be
  140.     ** a related scrollbar. */
  141.  
  142. TEHandle        CTEFromScroll(ControlHandle scrollCtl, ControlHandle *retCtl);
  143.     /* Find the TextEdit record that is related to the indicated scrollbar. */
  144.  
  145. Rect            CTEHide(TEHandle teHndl);
  146.     /* Hide the designated TextEdit control and related scrollbars. */
  147.  
  148. void            CTEIdle(void);
  149.     /* Blink the caret in the active TextEdit control.  The active TextEdit
  150.     ** control may be read-only, in which case the caret does not blink. */
  151.  
  152. short            CTEKey(WindowPtr window, EventRecord *event);
  153.     /* See if the keypress event applies to the TextEdit control, and if it does,
  154.     ** handle it and return non-zero.
  155.     **
  156.     ** if CTEKey returns 0, TextEdit control didn't handle the event.
  157.     ** if CTEKey returns 1, TextEdit control did handle the event, but the TERecord didn't change.
  158.     ** if CTEKey returns 2, TextEdit control did handle the event, and the TERecord changed. */
  159.  
  160. void            CTEMove(TEHandle teHndl, short newH, short newV);
  161.     /* This function is used to move a TextEdit control.  Pass it the TextEdit
  162.     ** record to move, plus the new position.  It will move the TextEdit control,
  163.     ** along with any scrollbars the control may have.  All areas that need
  164.     ** updating are cleared and invalidated. */
  165.  
  166. OSErr            CTENew(short viewID, Boolean vis, WindowPtr window, TEHandle *teHndl, Rect *cRect,
  167.                        Rect *dRect, Rect *vRect, Rect *bRect, short maxTextLen, short mode);
  168.     /* Create a new TextEdit control.  See the file ā€œ=Using TextEditControl.cā€ for more
  169.     ** information on this call. */
  170.  
  171. void            CTENewUndo(ControlHandle viewCtl, Boolean alwaysNewUndo);
  172.     /* Save the data (if appropriate) so that user can undo. */
  173.  
  174. ControlHandle    CTENext(WindowPtr window, TEHandle *teHndl, ControlHandle ctl, short dir, Boolean justActive);
  175.     /* Get the next TextEdit control in the window.  You pass it a control handle
  176.     ** for the view control, or nil to start at the beginning of the window.
  177.     ** It returns both a TextEdit handle and the view control handle for that
  178.     ** TextEdit record.  If none is found, nil is returned.  This allows you to
  179.     ** repeatedly call this function and walk through all the TextEdit controls
  180.     ** in a window. */
  181.  
  182. short            CTENumTextLines(TEHandle teHndl);
  183.     /* Return the number of lines of text.  This is because there is a bug in
  184.     ** TextEdit where the number of lines returned is incorrect if the text
  185.     ** ends with a c/r.  This function adjusts for this bug. */
  186.  
  187. OSErr            CTEPrint(TEHandle teHndl, short *offset, Rect *rct);
  188.     /* Use this function to print the contents of a TextEdit record.  Pass it a
  189.     ** TextEdit handle, a pointer to a text offset, and a pointer to a rect to
  190.     ** print the text in.  The offset should be initialized to what character
  191.     ** in the TextEdit record you wish to start printing at (most likely 0).
  192.     ** The print function prints as much text as will fit in the rect, and
  193.     ** then updates the offset to tell you what is the first character that didn't
  194.     ** print.  You can then call the print function again with another rect with
  195.     ** this new offset, and it will print the text starting at the new offset.
  196.     ** This method is very useful when a single TextEdit record is longer than a
  197.     ** single page, and you wish the text to break at the end of the page.
  198.     ** The bottom of rect is also updated, along with the offset.  The bottom edge
  199.     ** of the rect is changed to reflect the actual bottom of the text printed.
  200.     ** This is useful because the rect passed in didn't necessarily hold an
  201.     ** integer number of lines of text.  The bottom of the rect is adjusted so
  202.     ** it exactly holds complete lines of text.
  203.     ** It is also possible that the rect could hold substantially more lines of
  204.     ** text than there are remaining.  Again, in this situation, the bottom of
  205.     ** rect is adjusted so that the rect tightly bounds the text printed.
  206.     ** The remaining piece of information passed back is an indicator that the
  207.     ** text through the end of the TextEdit record was printed.  When the end
  208.     ** of the text is reached, the offset for the next text to be printed is
  209.     ** returned as -1.  This indicates that processing of the TextEdit record
  210.     ** is complete. */
  211.  
  212. Boolean            CTEReadOnly(TEHandle teHndl);
  213.     /* Return if the TextEdit control is read-write (true) or read-only (false). */
  214.  
  215. ControlHandle    CTEScrollFromTE(TEHandle teHndl, Boolean vertScroll);
  216.     /* Return the control handle for the TextEdit control's scrollbar, either
  217.     ** vertical or horizontal.  If the scrollbar doesn't, nil is returned. */
  218.  
  219. ControlHandle    CTEScrollFromView(ControlHandle viewCtl, Boolean vertScroll);
  220.     /* Return the control handle for the scrollbar related to the view control,
  221.     ** either horizontal or vertical.  If the scrollbar doesn't exist, return nil. */
  222.  
  223. void            CTESetKeyFilter(TEHandle teHndl, CTEKeyFilterProcPtr proc);
  224.     /* A TextEdit control can have an optional key filter, which is called whenever
  225.     ** CTEKey() is called.  If you pass in nil, then the filtering is turned off.
  226.     ** This allows individual TextEdit controls to handle their own filtering.
  227.     ** The filter procedure is of the form:
  228.     **     Boolean (*CTEKeyFilterProcPtr)(TEHandle teHndl, EventRecord *event, Boolean *handled);
  229.     ** If true is returned, then CTEKey() is aborted, and the value in "handled" is
  230.     ** returned.  By having a separate abort value and return value, you can determine
  231.     ** if processing of the event should be continued or not, independent of whether
  232.     ** or not you aborted CTEKey(). */
  233.  
  234. void            CTESetFastKeys(TEHandle teHndl, CTEFastKeysProcPtr proc);
  235.     /* Set your own fast-keys procedure.  The fast-keys procedure returns whether or not
  236.     ** the particular keypress can be handled without returning to the application. */
  237.  
  238. void            CTESetSelect(short start, short end, TEHandle teHndl);
  239.     /* Select a range of text.  TESetSelect can't be used alone because it doesn't
  240.     ** update the scrollbars.  This function calls TESetSelect, and then fixes up
  241.     ** the scrollbars. */
  242.  
  243. void            CTEShow(TEHandle teHndl);
  244.     /* Show the designated TextEdit control and related scrollbars. */
  245.  
  246. void            CTESize(TEHandle teHndl, short newH, short newV, Boolean newDest);
  247.     /* This function is used to resize a TextEdit control.  Pass it the TextEdit
  248.     ** record to resize, plus the new horizontal and vertical size.  It will
  249.     ** resize the TextEdit control, realign the text, if necessary, plus it will
  250.     ** resize and adjust any scrollbars the TextEdit control may have.  All areas
  251.     ** that need updating are cleared and invalidated. */
  252.  
  253. Handle            CTESwapText(TEHandle teHndl, Handle newText, StScrpHandle styl, Boolean update);
  254.     /* Swap the TextEdit text handle with the text handle passed in.  If a non-nil styl
  255.     ** value is passed in, apply the style scrap to the new text. */
  256.  
  257. WindowPtr        CTETargetInfo(TEHandle *teHndl, Rect *teView);
  258.     /* Return information for the currently active TextEdit control.  The currently
  259.     ** active TextEdit control is stored in gActiveTEHndl, and can be accessed
  260.     ** directly.  If gActiveTEHndl is nil, then there is no currently active one.
  261.     ** The information that we return is the viewRect and window of the active
  262.     ** TextEdit control.  This is information that could be gotten directly, but
  263.     ** this call makes it a little more convenient. */
  264.  
  265. ControlHandle    CTEUndo(void);
  266.     /* Perform an undo function for the TextEdit control.
  267.     ** If a TextEdit control content changes due to this operation, the control
  268.     ** handle is returned. */
  269.  
  270. void            CTEUpdate(TEHandle teHndl, ControlHandle ctl, Boolean justShowActive);
  271.     /* Draw the TextEdit control and frame. */
  272.  
  273. ControlHandle    CTEViewFromTE(TEHandle teHndl);
  274.     /* Return the control handle for the view control that owns the TextEdit
  275.     ** record.  Use this to find the view to do customizations such as changing
  276.     ** the update procedure for this TextEdit control. */
  277.  
  278. TEHandle        CTEWindActivate(WindowPtr window, Boolean displayIt);
  279.     /* Call this when a window with TextEdit controls is being activated.  This
  280.     ** will make the TextEdit control that was last active in this window the
  281.     ** active TextEdit control again. */
  282.  
  283. void            CTEAdjustTEBottom(TEHandle teHndl);
  284.     /* This function is called after an edit to make sure that there is no extra
  285.     ** white space at the bottom of the viewRect.  If there are blank lines at
  286.     ** the bottom of the viewRect, and there is text scrolled off the top of the
  287.     ** viewRect, then the TextEdit control is scrolled to fill this space, or as
  288.     ** much of it as possible. */
  289.  
  290. void            CTEAdjustScrollValues(TEHandle teHndl);
  291.     /* Bring the scrollbar values up to date with the current document position
  292.     ** and length. */
  293.  
  294. StScrpHandle    CTEGetFullStylScrap(TEHandle teHndl);
  295.     /* This function gets the style scrap for the entire TextEdit control.  It doesn't
  296.     ** matter what the current selection range is.  The TextEdit control is left unaffected. */
  297.  
  298. void            CTESetStylScrap(short begRng, short endRng, StScrpHandle styles, TEHandle teHndl);
  299.     /* This function applies the style scrap to the TextEdit record.  This function works better
  300.     ** than the toolbox function TESetStylScrap(). */
  301.  
  302. short            CTEGetLineNum(TEHandle te, short offset);
  303.     /* This function returns the line number associated with the offset passed in. */
  304.  
  305. short            CTEGetLineHeight(TEHandle te, short lineNum, short *ascent);
  306.     /* This function returns the line height of the requested line number. */
  307.  
  308. void            CTEGetPStr(ControlHandle ctl, StringPtr pstr);
  309.     /* This function returns the TextEdit control text as a pascal string.  The maximum text
  310.     ** returned is 255 chars. */
  311.  
  312. void            CTESetPStr(ControlHandle ctl, StringPtr pstr);
  313. #define            CTEPutPStr CTESetPStr
  314.     /* This function sets the TextEdit control text to the pascal string. */
  315.  
  316. Boolean            CTEUseTSMTE(void);
  317.     /* Call this function if you want the TextEdit control to use TSMTE.  You still need to
  318.     ** register and unregister your application with the TextServices Manager.  That isn't
  319.     ** handled for you.  AppWannabe's Start.c file shows how this is done:
  320.     **
  321.     **    if(CTEUseTSMTE())
  322.     **        InitTSMAwareApplication();
  323.     **
  324.     **    ... do app things here ...
  325.     **
  326.     **    if(CTEUseTSMTE())
  327.     **        CloseTSMAwareApplication();
  328.     **
  329.     **    ExitToShell();
  330.     */
  331.  
  332. Boolean            TSMTEAvailable(void);
  333.     /* This function says if the TextServices init TSMTE is available for inline-input for
  334.     ** TextEdit.  Note that you should do the following at startup:
  335.     **
  336.     **         if(TSMTEAvailable())
  337.     **            InitTSMAwareApplication();
  338.     **
  339.     ** And at application shutdown, you should do the following:
  340.     **
  341.     **         if(TSMTEAvailable())
  342.     **            CloseTSMAwareApplication();
  343.     */
  344.  
  345.  
  346. typedef void            (*CTEActivateProcPtr)(Boolean active, TEHandle teHndl);
  347. typedef Boolean            (*CTEClickProcPtr)(WindowPtr window, EventRecord *event, short *action);
  348. typedef ControlHandle    (*CTECtlHitProcPtr)(void);
  349. typedef TEHandle        (*CTEFindActiveProcPtr)(WindowPtr window);
  350. typedef short            (*CTEKeyProcPtr)(WindowPtr window, EventRecord *event);
  351. typedef ControlHandle    (*CTENextProcPtr)(WindowPtr window, TEHandle *teHndl, ControlHandle ctl, short dir, Boolean justActive);
  352. typedef void            (*CTESetSelectProcPtr)(short start, short end, TEHandle teHndl);
  353. typedef ControlHandle    (*CTEViewFromTEProcPtr)(TEHandle teHndl);
  354. typedef TEHandle        (*CTEWindActivateProcPtr)(WindowPtr window, Boolean displayIt);
  355.  
  356. #define rTECtl                4000
  357.  
  358. #define cteReadOnly            0x0001
  359. #define cteHScroll            0x0002
  360. #define cteHScrollLessGrow    0x0006
  361. #define cteVScroll            0x0008
  362. #define cteVScrollLessGrow    0x0018
  363. #define cteActive            0x0020
  364. #define cteNoBorder            0x0040
  365. #define cteShowActive        0x0080
  366. #define cteTabSelectAll        0x0100
  367. #define cteTwoStep            0x0200
  368. #define cteScrollFullLines    0x0400
  369. #define cteStyledTE            0x0800
  370. #define cteCenterJustify    0x1000
  371. #define cteRightJustify        0x2000
  372. #define cteNoFastKeys        0x4000
  373. #define cteTSMTE            0x8000
  374.  
  375. #endif
  376.